package com.bwie.pay.config;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

//@Configuration

@Data
@Component
//读取yml文件中alipay 开头的配置
@ConfigurationProperties(prefix = "alipay")
public class AliPayConfig {
//    @Bean
//    public Config getOptions() {
//        Config config = new Config();
//        config.protocol = "https";
//        config.gatewayHost = "openapi-sandbox.dl.alipaydev.com";
//        config.signType = "RSA2";
//        config.appId = "2021000143604975";
//        // 为避免私钥随源码泄露，推荐从文件中读取私钥字符串而不是写入源码中
//        config.merchantPrivateKey = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDBJzlXj7BKABX0z/bDcSIMesdR4eJJBjN28qsfYbWK4rR/7KMZpZGh2EdCkdMSw9xgIhyjTdM4lHbGVm5tXn7a5AGpm3327UbNSXNmhp67vusPz4iAgSXXwZSPyOpp9EMcAMTkNVLS4WUe/0VQQVmjUZNYwtPISM78iSwKpPX0sJSYkNfLkz325hRAN7of9djsCe9TZnE19RomrIVdTW950F6qg5SkNd9PgdsdTXWUMi3GA63JdIOWLbiI/Qf93kg91foW/GWhsZkic/OOSzAuhcipJMqEODxkIsjpD8g9zL7t8QadB9s05ub+zDuuQQuk5b3Fyc3a3ZnGItgVasJZAgMBAAECggEBAJEwmdLu6JYHkHmQpa3t6ak11YQAZqd7qM3dxbH2MY+vr/yE9Wj+4wSkXZR1pxLw9UOyAJLkmkRqnQmjyKgfov2I7JMAleQ6IcGIV92WjdUUwv8EglgOPFL9aV3XqhVxDc0L6vSb/KEV2nw9aG3WYbn5ROgwsx9XU3fS6K8rptKBZxo+LYP6Pd7Fx+hGSJ4FG62Or5rYvP+vf0KxjoVDGWnjNuBCcKJ67kyHuQtLQPm0H3rWxFX2ZYAy8eLFr+qMcFyTODKwcFgkUWlWTKBNORaVqfIaMtKrC5Q0iZN9xVgrb0qAh+S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dSMTHs3FgSVPjWJsTlFoN5NQ+U/SIT90urA3SGjSOXONu7KRN9PgFb/BehtyvsiQ33J5Z2sMZ1ZHKv0NR1WehRsLKVHrwE1rJCMXiV22x+SyzVNHsljPeloMwCdVdEwIob2jQLmHdLxCq5riRpSaQNqBD37eFWb6b9mbQf6ZSE3AffmaNIBp5D+pO48AQhsJf9gMAXljkKpskJvuDwGfvQa9yf2wGWf4WJhKUDURY4fuBiuJr/OpJ6F7ZQIDAQAB";
//        //可设置异步通知接收服务地址（可选）
//        config.notifyUrl = "http://3t75ya.natappfree.cc/pay/Result";
//        return config;
//    }


    private String appId;
    private String appPrivateKey;
    private String alipayPublicKey;
    private String notifyUrl;
    private String returnUrl;

    @PostConstruct
    public void init() {
        // 设置参数（全局只需设置一次）
        Config config = new Config();
        config.protocol = "https";
        config.gatewayHost = "openapi-sandbox.dl.alipaydev.com";
        config.signType = "RSA2";
        config.appId = this.appId;
        config.merchantPrivateKey = this.appPrivateKey;
        config.alipayPublicKey = this.alipayPublicKey;
        config.notifyUrl = this.notifyUrl;
        Factory.setOptions(config);
        System.out.println("=======支付宝SDK初始化成功=======");
    }
}
